package subject_set.interview.Day4_9_zijie;

/**
 * @author haomin
 * @date 2023/04/09 20:55
 **/
import java.util.*;
import java.util.Scanner;

public class Main4{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            String[] strs = in.nextLine().trim().split(" ");
            int n = Integer.parseInt(strs[0]);
            int m = Integer.parseInt(strs[1]);
            int k = Integer.parseInt(strs[2]);
            String[] arrs = in.nextLine().trim().split(" ");
            int[] arr = new int[arrs.length];
            int[] arr2 = new int[arr.length];
            for(int i = 0; i < arrs.length; ++i) {
                arr[i] = Integer.parseInt(arrs[i]);
            }
            Arrays.sort(arr);
            while(m-- > 0) {
                int kc = k;
                int l = 0, r = arr.length-1;
                int sum = 0;
                int p = Integer.parseInt(in.nextLine().trim());
                while(p-- > 0) {
                    if(kc > 0) {
                        if(arr[l] < arr[r]) {
                            sum += arr[r] * arr[r];
                            r--;
                        }else {
                            sum += arr[l] * arr[l];
                            l++;
                        }
                        kc--;
                    }else {
                        sum += arr[r];
                        r--;
                    }
                }
                System.out.println(sum);
            }

        }
    }
}